From 1d513f05bae4ba8a3ff5d609806be9161b1b9d73 Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Fri, 16 Apr 2004 15:37:30 +0000 Subject: [PATCH] Add 'encrypt' option to text, html outputs to keep the hint at least a little secret. --- gpsbabel/defs.h | 2 ++ gpsbabel/html.c | 11 ++++++++++- gpsbabel/text.c | 11 ++++++++++- gpsbabel/util.c | 24 +++++++++++++++++++++++- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index d08d71146..50e540fe8 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -422,6 +422,8 @@ char * strip_nastyhtml(const char * in); char * str_utf8_to_cp1252( const char * str ); char * str_utf8_to_ascii( const char * str ); +char * rot13( const char *str ); + /* * PalmOS records like fixed-point numbers, which should be rounded * to deal with possible floating-point representation errors. diff --git a/gpsbabel/html.c b/gpsbabel/html.c index 8a128bb5c..8b32e5448 100644 --- a/gpsbabel/html.c +++ b/gpsbabel/html.c @@ -28,6 +28,7 @@ static FILE *file_out; static void *mkshort_handle; static char *stylesheet = NULL; +static char *encrypt = NULL; #define MYNAME "HTML" @@ -35,6 +36,8 @@ static arglist_t html_args[] = { { "stylesheet", &stylesheet, "Path to HTML style sheet", ARGTYPE_STRING }, + { "encrypt", &encrypt, + "Encrypt hints using ROT13", ARGTYPE_BOOL }, {0, 0, 0, 0} }; @@ -104,7 +107,13 @@ html_disp(const waypoint *wpt) fprintf (file_out, "

%s

\n", strip_nastyhtml(wpt->gc_data.desc_long.utfstring)); } if (wpt->gc_data.hint) { - fprintf (file_out, "

Hint: %s

\n", wpt->gc_data.hint); + char *hint = NULL; + if ( encrypt ) + hint = rot13( wpt->gc_data.hint ); + else + hint = xstrdup( wpt->gc_data.hint ); + fprintf (file_out, "

Hint: %s

\n", hint); + xfree( hint ); } } else if (strcmp(wpt->notes,wpt->description)) { diff --git a/gpsbabel/text.c b/gpsbabel/text.c index cebd5a835..180a9b977 100644 --- a/gpsbabel/text.c +++ b/gpsbabel/text.c @@ -28,6 +28,7 @@ static FILE *file_out; static void *mkshort_handle; static char *suppresssep = NULL; +static char *encrypt = NULL; #define MYNAME "TEXT" @@ -35,6 +36,8 @@ static arglist_t text_args[] = { { "nosep", &suppresssep, "Suppress separator lines between waypoints", ARGTYPE_BOOL }, + { "encrypt", &encrypt, + "Encrypt hints using ROT13", ARGTYPE_BOOL }, {0, 0, 0, 0} }; @@ -97,7 +100,13 @@ text_disp(const waypoint *wpt) xfree(stripped_html); } if (wpt->gc_data.hint) { - fprintf (file_out, "\nHint: %s\n", wpt->gc_data.hint); + char *hint = NULL; + if ( encrypt ) + hint = rot13( wpt->gc_data.hint ); + else + hint = xstrdup( wpt->gc_data.hint ); + fprintf (file_out, "\nHint: %s\n", hint); + xfree( hint ); } } else if (strcmp(wpt->notes,wpt->description)) { diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 010684d8a..0d3505c9f 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -628,7 +628,29 @@ strsub(char *s, char *search, char *replace) strcat(d, p + slen); return d; } - + +char * +rot13( const char *s ) +{ + char *result = xstrdup( s ); + char *cur = result; + int flip = 1; + while (cur && *cur ) { + if ( flip ) { + if (*cur == '[') flip = 0; + else if ( *cur >= 'A' && *cur <= 'Z' ) { + *cur = 'A' + ((*cur-'A')+13)%26; + } + else if ( *cur >= 'a' && *cur <= 'z' ) { + *cur = 'a' + ((*cur-'a')+13)%26; + } + } + else if ( *cur == ']' ) flip = 1; + cur++; + } + return result; +} + void utf8_to_int( const char *cp, int *bytes, int *value ) { if ( (*cp & 0xe0) == 0xc0 ) { -- 2.30.2